package com.compass.web;

import com.compass.service.CallService;
import com.compass.thread.Worker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Random;

@RestController
public class WebController {
    @Autowired
    @Qualifier("callService")
    CallService callService;

    @RequestMapping("/hi")
    public String hi(String name){
        return callService.sayHi(name);
    }

    /*
      *@Author zhangBo
      *@Since ver 1.0
      *@Date 17-9-19 下午2:42
      *@Description
      */
    @RequestMapping("sell")
    public String sell(String itemName,int num){
        return callService.sell(itemName,num);
    }


    @RequestMapping("buy")
    public String buy(String itemName,int num){
        return callService.buy(itemName,num);
    }

    @RequestMapping("auto")
    public String auto(){
        int m = 1000;
        while (m>0){
            Random random = new Random();
            int i = random.nextInt(5)+1;
            String itemName = String.valueOf((char)(i+64));
            Worker worker = new Worker(callService, itemName, i);
            Thread thread = new Thread(worker);
            thread.start();
            m--;
        }
        return "ok";
    }

}
